<template>
  <div class="practiceList-box">
  	<el-row :gutter="10">
  		<el-col :span="3"><el-button @click="$router.push({path:'practiceAddForm',query:{is_sim:'true'}})">+ 新增</el-button></el-col>
  	</el-row>
    <Table
      :tableData="tableData.data"
      :inits="tableinits"
      :operation="operationinits">
      <template slot-scope="{rowScope}">
        <el-button @click="$router.push({path:'practiceAddForm',query:{id:rowScope.row.id,is_sim:'true',checkmode:'true'}})" type="text" size="small">查看</el-button>
        <el-button @click="$router.push({path:'practiceAddForm',query:{id:rowScope.row.id,is_sim:'true'}})" type="text" size="small">编辑</el-button>
        <el-button @click="del(rowScope)" type="text" size="small">删除</el-button>
      </template>
    </Table>
		<el-row>
			<el-col>
				<el-pagination
					layout="prev, pager, next"
					:page-size="15"
					:current-page="tableData.page"
					:total="tableData.total"
					@current-change="pageNoChange">
				</el-pagination>
			</el-col>
		</el-row>
  </div>
</template>

<script>
import Table from '@/components/Table'

export default {
  name: 'PracticeList',
  components: {
    Table
  },
  data () {
    return {
    	 input: '',
      tableData: {
				page:1,
				total:0,
				data:[]
			},
      tableinits: [
        { label: '编号', width: '55', prop: 'id' },
        { label: '练习名称', prop: 'name' },
        { label: '更新时间', prop: 'updated_at' },
        { label: '创建时间', prop: 'created_at' }
      ],
      operationinits: { width: '100', label: '操作' }
    }
  },
	created(){
		this.getdata({sim:1})
	},
  methods: {
		getdata(params){
			this.$API.getPracticeList(params).then(res=>{
				this.tableData.data = res.data;
				this.tableData.total=res.total
			})
		},
		pageNoChange(index){
			this.getdata({sim:1,page:index})
		},
    edit (scope) {
      console.log(scope)
      this.$message.info({
        message: `编辑按钮被按下`
      })
    },
    del (scope) {
      this.$confirm('确认删除吗？', '提示', {
      		type: 'warning'
      	})
      .then(() => {
      		this.$API.delExam(scope.row.id)
      		.then(data => {
      			this.getdata({sim:1})
      	 })
				}).catch(err=>{})
    }
  }
}
</script>

<style>
.practiceList-box {
  text-align: left;
}
</style>
